Skip to content

Refactor crop generation module as subpackage to avoid single module expanding indefinitely with added features#32

Open
wli51 wants to merge 3 commits into
WayScience:mainfrom
wli51:refactor-crop-gen
Open

Refactor crop generation module as subpackage to avoid single module expanding indefinitely with added features#32
wli51 wants to merge 3 commits into
WayScience:mainfrom
wli51:refactor-crop-gen

Conversation

@wli51

@wli51 wli51 commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

The original src/virtual_stain_flow/datasets/ds_engine/crop_generator.py houses the protocol and two types of crop generating function. As more functionalities are added the single module would expand making it hard to read and maintain. So I decided to refactor the crop generation module as a sub package. Also added a new tiling crop generator.

wli51 added 3 commits June 10, 2026 09:34
…ated as a subpackage, moved crop generator protocol to its own stand aloen module and center and point-centered crop generator functions in their respective modules under the new subpackage.
…ubpackage while supporting older import signatures for compatibility

@MikeLippincott MikeLippincott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Good PR. Please let me know if any of my comments/questions do not make sense.

Last thing here that should probably be added in this PR or another PR are tests for these functions/classes! Do they behave how you expect them to?

manifest = dataset.file_state.manifest
crop_specs: Dict[int, List[Tuple[Tuple[int, int], int, int]]] = {}

for idx in range(len(dataset)):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using enumerate here?

Comment on lines +35 to +38
if x <= crop_size // 2 or x >= image_width - crop_size // 2 or \
y <= crop_size // 2 or y >= image_height - crop_size // 2:
continue # Skip points too close to the edge for a full crop

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be nice to log at the least counts of crops that get skipped here to understand X% of crops were too close to the edge

Comment on lines +66 to +73
if crop_size is None:
raise ValueError(
"crop_size must be provided for point-centered crop generation."
)
if mapping is None:
raise ValueError(
"mapping must be provided for point-centered crop generation."
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you check for float/int instead?

dataset: BaseImageDataset,
**kwargs: Any
) -> CropMap:
pass

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this supposed to be empty?

I see the inhertence in the class but nothing else? Later PR potentially?

Compute 1D tile start positions for non-overlapping tiles centered
within an image extent.

:param image_extent: Size of image extent along one axis (width or height).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this assume isometric X and Y

Comment on lines +80 to +85
Generate best-effort centered, non-overlapping tiling crops
for each sample in a BaseImageDataset.

Tiling is "best-effort" in that it uses as many full, non-overlapping
tiles of size `crop_size` as possible along each axis, then centers
the tile grid within the remaining field of view.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why non-overlapping? Consider adding a single sentence on why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants